package com.rw.car.utils;

import com.rw.car.cache.RedisCache;
import com.rw.car.pojo.ConfigInfo;
import com.rw.car.service.ConfigInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class LoadMsqlToRedis implements CommandLineRunner {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private ConfigInfoService configInfoService;

    @Override
    public void run(String... args) throws Exception {
     //   此处讲mysql的数据加载到redis
        System.out.println("初始化后进行执行");
        List<ConfigInfo> list = configInfoService.getAll();

        for(ConfigInfo item:list){
            redisCache.set(item.getConfigKey(),item.getConfigValue());
        }
        System.out.println("加载结束");
    }
}
